//
//  CLDiagnosisDetailsController.m
//  CareLink
//
//  Created by whong7 on 16/8/19.
//  Copyright © 2016年 Seven Team. All rights reserved.
//

#import "CLDiagnosisDetailsController.h"
#import "CLDiseaseStyleModel.h"
//设定cellid
static NSString *cellid = @"diseaseStyle_cell";

@interface CLDiagnosisDetailsController ()

@property(nonatomic,strong)NSDictionary *styleSwitch;

@end

@implementation CLDiagnosisDetailsController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}


-(void)setupUI
{
    //view布局
    self.view.backgroundColor = [UIColor colorWithHex:0xF5F5F5];
    
    //注册单元格
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    
    //去掉多余的线
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
    
    [self.tableView setTableFooterView:v];
    //建立治疗选项字典
    NSDictionary *dict = @{@"2" : @"手术治疗" , @"3" : @"保守治疗", @"4" : @"药物治疗"};
    self.styleSwitch = dict;
#warning mark ---------设置返回按钮文字为空
    // 设置返回的按钮的文字为空
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}


#pragma mark - 数据源方法

//某一组有多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
//cell的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
 
    //取缓存池找
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
    NSString *key = [NSString stringWithFormat:@"%ld",indexPath.row+2];
    cell.textLabel.text = self.styleSwitch[key];
    cell.textLabel.textColor = [UIColor colorWithHex:0x666666];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    //去掉cell的颜色
    cell.backgroundColor = [UIColor clearColor];

    
    //设置有箭头
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}


#pragma mark - 代理方法
//被选中的时候 运行
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *key = [NSString stringWithFormat:@"%ld",indexPath.row+2];
    //取出被选中的键值对
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setObject:self.styleSwitch[key] forKey:key];
    
    
    // 这句话的意思 就是让table是否以动画的形式 取消indexPath这个位置的背景色
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.inputCompeletionBlock != nil) {
        self.inputCompeletionBlock(dict.copy);
    }
    [self.navigationController popViewControllerAnimated:YES];
    
}



#pragma mark - 取消系统线

- (void)viewDidLayoutSubviews
{ if([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{ [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)]; }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
    { [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)]; } }

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{ if ([cell respondsToSelector:@selector(setSeparatorInset:)])
{
    [cell setSeparatorInset:UIEdgeInsetsZero];
}
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
@end
